home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / BIOLOGY / GSRC208A.ZIP / IOTOP.C < prev    next >
C/C++ Source or Header  |  1993-08-26  |  17KB  |  642 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992, 1993  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*        MS-WINDOWS front end       */
  11. /*                                   */
  12. /*         Topology files I/O        */
  13. /*                                   */
  14. /*          QuickC/WIN 1.0           */
  15. /*                                   */
  16. /*   (include here compilers that    */
  17. /*   compiled GWSIM successfully)    */
  18. /*                                   */
  19. /*************************************/
  20.  
  21.  
  22. /*
  23.   this file is used both by GWSIM and GWTOP and GWTOP
  24.   must define the symbol GWTOP, otherwise, this file
  25.   will generate stuff for GWSIM
  26. */
  27.  
  28. #include <windows.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <io.h>
  33. #include <sys\types.h>
  34. #include <sys\stat.h>
  35. #include "globals.h"
  36. #include "iotop.h"
  37. #include "strtbl.h"                        /* symbols for the string table            */
  38. #ifdef GWTOP
  39. #include "gwtop.h"
  40. #include "topgvar.h"
  41. #include "gep1.h"
  42. #else
  43. #include "gwsim.h"
  44. #include "simgvar.h"
  45. #include "gep2.h"
  46. #endif
  47.  
  48. #pragma alloc_text( CODE12, TreeToBuf, BufToTree, TopToBuf, WriteTop, BufToTop, ReadTop )
  49.  
  50. /* write a rate equation tree to a buffer                            */
  51.  
  52. void TreeToBuf( int i, LPSTR Buff )
  53. {
  54.  char a1[128];
  55.  int j;
  56.  
  57.  wsprintf( (LPSTR) Buff, "\f%s\n", (LPSTR) tree[i].descr );
  58.  wsprintf( (LPSTR) a1, "%d %d %d %d %d %d %d %d\n", tree[i].nnode,
  59.                                                        tree[i].nid,
  60.                                                     tree[i].nnum,
  61.                                                     tree[i].nconst,
  62.                                                     tree[i].nsub,
  63.                                                     tree[i].npro,
  64.                                                     tree[i].nmodf,
  65.                                                     tree[i].revers );
  66.  lstrcat( Buff, (LPSTR) a1 );
  67.  for( j=0; j<tree[i].nnode; j++ )
  68.  {
  69.   wsprintf( (LPSTR) a1, "%c %d %d %d,", tree[i].node[j].item, (int) tree[i].node[j].val,
  70.                                   (int) tree[i].node[j].left, (int) tree[i].node[j].right );
  71.   lstrcat( Buff , (LPSTR) a1 );
  72.  }
  73.  lstrcat( Buff, (LPSTR) "\n" );
  74.  for( j=0; j<tree[i].nid; j++ )
  75.  {
  76.   wsprintf( (LPSTR) a1, "%d %s\n", (int) tree[i].id[j][9], (LPSTR) tree[i].id[j] );
  77.   lstrcat( Buff, (LPSTR) a1 );
  78.  }
  79.  for( j=0; j<tree[i].nnum; j++ )
  80.  {
  81.   gcvt( tree[i].constant[j], 8, a1 );
  82.   lstrcat( Buff, (LPSTR) a1 );
  83.   lstrcat( Buff, (LPSTR) "\n" );
  84.  }
  85. }
  86.  
  87.  
  88. char *BufToTree( char *Buff )
  89. {
  90.  int i;
  91.  char *paux;
  92.  int daux, daux1, daux2;
  93.  char caux[10];
  94.  float faux;
  95.  
  96.  /* copy the title from the buffer                                */
  97.  paux = strchr( Buff, '\n' );
  98.  if( paux == NULL )
  99.   return (char *) NULL;
  100.  /* take care of CR if one existed before LF                        */
  101.  if( *(paux-1)=='\r' ) *(paux-1) = '\0';
  102.  *paux = '\0';
  103.  if( strlen( Buff ) > 63 ) Buff[63] = '\0';
  104.  lstrcpy( (LPSTR) tr.descr, (LPSTR) Buff );
  105.  Buff = paux+1;
  106.  
  107.  /* read nnode from the buffer                                        */
  108.  if ( sscanf( Buff, "%d", &daux ) < 1 )
  109.   return (char *) NULL;
  110.  tr.nnode = daux;
  111.  
  112.  Buff = strchr( Buff, ' ' );
  113.  /* read nid from the buffer                                        */
  114.  if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  115.   return (char *) NULL;
  116.  tr.nid = daux;
  117.  
  118.  Buff = strchr( Buff, ' ' );
  119.  /* read nnum from the buffer                                        */
  120.  if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  121.   return (char *) NULL;
  122.  tr.nnum = daux;
  123.  
  124.  Buff = strchr( Buff, ' ' );
  125.  /* read nconst from the buffer                                    */
  126.  if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  127.   return (char *) NULL;
  128.  tr.nconst = daux;
  129.  
  130.  Buff = strchr( Buff, ' ' );
  131.  /* read nsub from the buffer                                        */
  132.  if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  133.   return (char *) NULL;
  134.  tr.nsub = daux;
  135.  
  136.  Buff = strchr( Buff, ' ' );
  137.  /* read npro from the buffer                                        */
  138.  if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  139.   return (char *) NULL;
  140.  tr.npro = daux;
  141.  
  142.  Buff = strchr( Buff, ' ' );
  143.  /* read nmodf from the buffer                                    */
  144.  if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  145.   return (char *) NULL;
  146.  tr.nmodf = daux;
  147.  
  148.  Buff = strchr( Buff, ' ' );
  149.  /* read revers from the buffer                                    */
  150.  if( (Buff == NULL ) || ( sscanf( ++Buff, "%d", &daux ) < 1 ) )
  151.   return (char *) NULL;
  152.  tr.revers = daux;
  153.  
  154.  Buff = strchr( Buff, '\n' );
  155.  if( Buff==NULL ) return (char *) NULL;
  156.  Buff++;
  157.  
  158.  for( i=0; i<tr.nnode; i++ )
  159.  {
  160.   if( ( sscanf( Buff, "%c %d %d %d", &caux[0],
  161.                                      &daux,
  162.                                      &daux1,
  163.                                      &daux2 ) < 4 ) )
  164.    return (char *) NULL;
  165.   tr.node[i].item  = caux[0];
  166.   tr.node[i].val   = (unsigned char) daux;
  167.   tr.node[i].left  = (unsigned char) daux1;
  168.   tr.node[i].right = (unsigned char) daux2;
  169.   Buff = strchr( Buff, ',' );
  170.   if( Buff==NULL ) return (char *) NULL;
  171.   Buff++;
  172.  }
  173.  for( i=0; i<tr.nid; i++ )
  174.  {
  175.   Buff = strchr( Buff, '\n' );
  176.   if( Buff==NULL ) return (char *) NULL;
  177.   Buff++;
  178.   if( sscanf( Buff, "%d %8s", &daux, caux ) < 2 )
  179.    return (char *) NULL;
  180.   lstrcpy( tr.id[i], (LPSTR) caux );
  181.   tr.id[i][8] = '\0';
  182.   tr.id[i][9] = (char) daux;
  183.  }
  184.  for( i=0; i<tr.nnum; i++ )
  185.  {
  186.   Buff = strchr( Buff, '\n' );
  187.   if( Buff==NULL ) return (char *) NULL;
  188.   Buff++;
  189.   if( sscanf( Buff, "%g", &faux ) < 1 )
  190.    return (char *) NULL;
  191.   tr.constant[i] = faux;
  192.  }
  193. /*Buff = strchr( Buff, '\n' );*/
  194.  return Buff;
  195. }
  196.  
  197.  
  198. void TopToBuf( LPSTR Buff )
  199. {
  200.  int i, j;
  201.  char auxstr[260];
  202.  
  203.  /* first line: version number                                            */
  204.  wsprintf( (LPSTR) Buff, FILE_VERSION );
  205.  /* topology's title in one line                                        */
  206.  wsprintf( (LPSTR) auxstr, "%s\n", (LPSTR) topname );
  207.  lstrcat( Buff, (LPSTR) auxstr);
  208.  /* number of steps and metabolites    in one line                            */
  209.  wsprintf( (LPSTR) auxstr, "%d %d\n", nsteps, totmet );
  210.  lstrcat( Buff, (LPSTR) auxstr);
  211.  /* stoicheiometry matrix                                                */
  212.  for(i=0;i<totmet;i++)
  213.  {
  214.   for(j=0;j<nsteps;j++)
  215.   {
  216. #ifdef GWTOP
  217.    wsprintf( (LPSTR) auxstr, "%2d ", stoiu[i*MAX_MET + j] );
  218. #else
  219.    wsprintf( (LPSTR) auxstr, "%2d ", stoi[i*MAX_MET + j] );
  220. #endif
  221.    lstrcat( Buff, (LPSTR) auxstr);
  222.   }
  223.   lstrcat( Buff, (LPSTR) "\n" );
  224.  }
  225.  /* kinetic types, reversability status and step names, one per line    */
  226.  for(i=0;i<nsteps;i++)
  227.  {
  228.   wsprintf( (LPSTR) auxstr, "%2d %2d %s\n", kinetu[i],
  229.                                               revers[i],
  230.                                               (LPSTR) stepname[i] );
  231.   lstrcat( Buff, (LPSTR) auxstr);
  232.  }
  233.  /* rstr matrix                                                            */
  234.  for(i=0;i<nsteps;i++)
  235.  {
  236.   for(j=0;j<MAX_MOL;j++)
  237.   {
  238.    wsprintf( (LPSTR) auxstr, "%2d ", (*rstr)[i][j] );
  239.    lstrcat( Buff, (LPSTR) auxstr);
  240.   }
  241.   lstrcat( Buff, (LPSTR) "\n" );
  242.  }
  243.  /* loop matrix                                                            */
  244.  for(i=0;i<nsteps;i++)
  245.  {
  246.   for(j=0;j<totmet;j++)
  247.   {
  248.    wsprintf( (LPSTR) auxstr, "%2d ", (*loop)[i][j] );
  249.    lstrcat( Buff, (LPSTR) auxstr);
  250.   }
  251.   lstrcat( Buff, (LPSTR) "\n" );
  252.  }
  253.  /* metabolite status and names, one per line                                        */
  254.  for(i=0;i<totmet;i++)
  255.  {
  256.   wsprintf( (LPSTR) auxstr, "%d %s\n", intmet[i], (LPSTR) metname[i] );
  257.   lstrcat( Buff, (LPSTR) auxstr );
  258.  }
  259. }
  260.  
  261. int WriteTop( LPSTR FName )
  262. {
  263.  GLOBALHANDLE hBuff;
  264.  HCURSOR hSaveCursor;
  265.  LPSTR Buff;
  266.  int ch1, i, udt;
  267.  WORD bufsize;
  268.  OFSTRUCT OfStruct;
  269.  
  270.  /* display the wait cursor                                            */
  271.  hSaveCursor = SetCursor(hHourGlass);
  272.  
  273.  /* set the maximum buffer size for the topology w/o user-def kin        */
  274.  bufsize = (WORD) (20 + 256 + 2 + 5 + 2 +
  275.                    totmet*(nsteps*3 + 2) +
  276.                    nsteps*(5 + NAME_L + 2) +
  277.                    nsteps*(MAX_MOL*4 + 2) +
  278.                    nsteps*(totmet*4 + 2) +
  279.                    totmet*(NAME_L + 2 + 2)
  280.                   );
  281.  hBuff = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, bufsize );
  282.  Buff = (LPSTR) GlobalLock( hBuff );
  283.  /* write the information on the buffer                                    */
  284.  TopToBuf( Buff );
  285.  /* open the file                                                        */
  286.  if( (ch1 = OpenFile( FName, &OfStruct, OF_CREATE | OF_WRITE )) != -1 )
  287.  {
  288.   /* write the buffer to the file and close it                            */
  289.   _lwrite( ch1, Buff, (WORD) lstrlen( Buff ) );
  290.   ch1 = _lclose( ch1 );
  291.  }
  292.  if( ch1 == -1 )
  293.  {
  294.   GlobalUnlock( hBuff );
  295.   GlobalFree( hBuff );
  296.   SetCursor(hSaveCursor);
  297.   return IDS_ERR_SAVE;
  298.  }
  299.  /* check if model contains user-defined kinetic types                    */
  300.  for( i=0, udt=0; i<nsteps; i++ )
  301.   if( kinetu[i] >= MAX_TYP )
  302.   {
  303.    udt = 1;
  304.    kfl[i] = 0;
  305.   }
  306.  /* if there are any, output them to the file                            */
  307.  if( udt )
  308.  {
  309.   /* reallocate Buff to accomodate one function                            */
  310.   udt = GlobalUnlock( hBuff );
  311.   hBuff = GlobalReAlloc( hBuff, (WORD) 5500 , GMEM_ZEROINIT | GMEM_MOVEABLE );
  312.   Buff = (LPSTR) GlobalLock( hBuff );
  313.   for( i=0; i<nsteps; i++ )
  314.    if( kinetu[i] >= MAX_TYP )
  315.    {
  316.     /* write the tree function to the buffer                            */
  317.     TreeToBuf( kinetu[i]-MAX_TYP, (LPSTR) Buff );
  318.     /* reopen the file and write this tree to it                        */
  319.     if( (ch1 = OpenFile( (LPSTR) NULL, &OfStruct, OF_REOPEN | OF_WRITE )) != -1 )
  320.     {
  321.      /* write the buffer to the file and close it                            */
  322.      _lseek( ch1, (LONG) 0, 2 );
  323.      _lwrite( ch1, (LPSTR) Buff, (WORD) lstrlen( Buff ) );
  324.      ch1 = _lclose( ch1 );
  325.     }
  326.     if( ch1 == -1 )
  327.     {
  328.      GlobalUnlock( hBuff );
  329.      GlobalFree( hBuff );
  330.      SetCursor(hSaveCursor);
  331.      return IDS_ERR_SAVE;
  332.     }
  333.     kfl[i] = 1;
  334.    }
  335.  }
  336.  GlobalUnlock( hBuff );
  337.  GlobalFree( hBuff );
  338.  SetCursor(hSaveCursor);
  339.  return 0;
  340. }
  341.  
  342. int BufToTop( char *Buff, char **endoftop )
  343. {
  344.  int i,j;
  345.  int daux;
  346.  unsigned char uaux;
  347.  char *paux;
  348.  char saux[NAME_L];
  349.  
  350.  /* reset the version number to zero                            */
  351.  ver_no = 0;
  352.  /* copy the first line                                            */
  353.  paux = strchr( Buff, '\n' );
  354.  if( paux == NULL )
  355.    return IDS_ERR_BAD_TOPNAM;
  356.  /* take care of CR if one existed before LF                    */
  357.  if( *(paux-1)=='\r' ) *(paux-1) = '\0';
  358.  *paux = '\0';
  359.  if( strlen( Buff ) > 255 ) Buff[255] = '\0';
  360.  lstrcpy( topname, (LPSTR) Buff );
  361.  Buff = paux+1;
  362.  /* is this line a version number ?                                */
  363.  sscanf( topname, "version %f", &ver_no );
  364.  if( ver_no != 0 )
  365.  {
  366.   /* YES! so let's read another line, with the title            */
  367.   paux = strchr( Buff, '\n' );
  368.   if( paux == NULL )
  369.    return IDS_ERR_BAD_TOPNAM;
  370.   if( *(paux-1)=='\r' ) *(paux-1) = '\0';
  371.   *paux = '\0';
  372.   if( strlen( Buff ) > 255 ) Buff[255] = '\0';
  373.   lstrcpy( topname, (LPSTR) Buff );
  374.   Buff = paux+1;
  375.  }
  376.  
  377.   /* read nstep from the buffer                                    */
  378.   if ( ( sscanf( Buff, " %d", &daux ) < 1) ||
  379.        ( daux < 1 ) || ( daux > MAX_STEP ) )
  380.    return IDS_ERR_BAD_NSTEP;
  381.   nsteps = daux;
  382.  
  383.   Buff = strchr( Buff, ' ' );
  384.   /* read totmet from the buffer                                */
  385.   if( (Buff == NULL ) || ( sscanf( ++Buff, " %d", &daux ) < 1) ||
  386.       ( daux < 1 )   || ( daux > MAX_MET ) )
  387.    return IDS_ERR_BAD_TOTMET;
  388.   totmet = daux;
  389.  
  390.   /* read stoiu from the buffer                                        */
  391.   for(i=0;i<totmet;i++)
  392.    for(j=0;j<nsteps;j++)
  393.    {
  394.     if(j==0)
  395.     {
  396.      Buff = strchr( Buff, '\n' );
  397.      if( Buff != NULL )
  398.      {
  399.       Buff++;
  400.       for( ;*Buff == ' '; Buff++);
  401.      }
  402.     }
  403.     else
  404.     {
  405.      Buff = strchr( Buff, ' ' );
  406.      if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
  407.     }
  408.     if ( (Buff == NULL) || (sscanf( Buff, "%d", &daux ) < 1) )
  409.      return IDS_ERR_BAD_STOI;
  410.     stoiu[i*MAX_MET + j] = daux;
  411.    }
  412.  
  413.   Buff = strchr( Buff, '\n' );
  414.   if( Buff == NULL )
  415.    return IDS_ERR_BAD_KINTYPE;
  416.   Buff++;
  417.   /* read kinetu, revers and metname from the buffer                */
  418.   for( i=0; i<nsteps; i++ )
  419.   {
  420.    for( ;*Buff == ' '; Buff++);
  421.    if ( (Buff == NULL) || (sscanf( Buff, "%d", &daux ) < 1)
  422.         || (daux < -1) )
  423.     return IDS_ERR_BAD_KINTYPE;
  424.    kinetu[i] = daux;
  425.  
  426.    Buff = strchr( Buff, ' ' );
  427.    if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
  428.    if ( (Buff == NULL) || (sscanf( Buff, "%d", &uaux ) < 1)
  429.         || (uaux < 0) || (uaux > 1) )
  430.     return IDS_ERR_BAD_KINTYPE;
  431.    revers[i] = uaux;
  432.  
  433.    Buff = strchr( Buff, ' ' );
  434.    if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
  435.    paux = strchr( Buff, '\n' );
  436.    if( paux == NULL )
  437.     return IDS_ERR_BAD_KINTYPE;
  438.    /* take care of CR if one existed before LF                        */
  439.    if( *(paux-1)=='\r' ) *(paux-1) = '\0';
  440.    *paux = '\0';
  441.    if( strlen( Buff ) >= NAME_L ) Buff[NAME_L-1] = '\0';
  442.    lstrcpy( (LPSTR) stepname[i], (LPSTR) Buff );
  443.    Buff = paux+1;
  444.   }
  445.  
  446.   *(--Buff) = '\n';
  447.   /* read rstr from the buffer                                        */
  448.   for(i=0;i<nsteps;i++)
  449.    for(j=0;j<MAX_MOL;j++)
  450.    {
  451.     if(j==0)
  452.     {
  453.      Buff = strchr( Buff, '\n' );
  454.      if( Buff != NULL )
  455.      {
  456.       Buff++;
  457.       for( ;*Buff == ' '; Buff++);
  458.      }
  459.     }
  460.     else
  461.     {
  462.      Buff = strchr( Buff, ' ' );
  463.      if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
  464.     }
  465.     if ( (Buff == NULL) || (sscanf( Buff,"%d", &daux ) < 1) )
  466.      return IDS_ERR_BAD_LOOP;
  467.     (*rstr)[i][j] = (signed char) daux;
  468.    }
  469.  
  470.   /* read loop from the buffer                                        */
  471.   for(i=0;i<nsteps;i++)
  472.    for(j=0;j<totmet;j++)
  473.    {
  474.     if(j==0)
  475.     {
  476.      Buff = strchr( Buff, '\n' );
  477.      if( Buff != NULL )
  478.      {
  479.       Buff++;
  480.       for( ;*Buff == ' '; Buff++);
  481.      }
  482.     }
  483.     else
  484.     {
  485.      Buff = strchr( Buff, ' ' );
  486.      if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
  487.     }
  488.     if ( (Buff == NULL) || (sscanf( Buff,"%u", &uaux ) < 1)
  489.           || (uaux < (unsigned) 0) )
  490.      return IDS_ERR_BAD_LOOP;
  491.     (*loop)[i][j] = uaux;
  492.    }
  493.  
  494.   /* read metabolite status and names from the buffer                */
  495.   for(i=0;i<totmet;i++)
  496.   {
  497.    Buff = strchr( Buff, '\n' );
  498.    if ( (Buff == NULL) || (sscanf( ++Buff, "%d %21s", &daux, &saux ) < 2) )
  499.     return IDS_ERR_BAD_INTMET;
  500.    intmet[i] = daux;
  501.    lstrcpy( metname[i], (LPSTR) saux );
  502.   }
  503.  
  504.   /* point endofbuf to the end of the topology section                */
  505.   if( endoftop != NULL )
  506.    *endoftop = Buff;
  507.  
  508.   return 0;
  509. }
  510.  
  511. /*
  512.   add a new function read from a .TOP file
  513.   and renumber references to this type in the .TOP
  514. */
  515.  
  516. int addtr( int e )
  517. {
  518.  int i, j, k, nRc;
  519.  
  520.  j = nudf;
  521.  k = kinetu[e];
  522.  eqefl = 0;
  523.  if( (nRc = new_tree( j )) != 0 ) return nRc;
  524.  if( (nRc = new_rateq( j )) != 0 ) return nRc;
  525.  for( i=e; i<nsteps; i++ )
  526.   if( (kinetu[i]==k) && (kfl[i]) )
  527.   {
  528.    kinetu[i] = MAX_TYP+j;
  529.    kfl[i] = 0;
  530.   }
  531.  notsaved = 1;
  532.  return 0;
  533. }
  534.  
  535.  
  536. /*
  537.     read topology from file
  538. */
  539.  
  540. int ReadTop( LPSTR FName )
  541. {
  542.  int i, j, k, fl, ty, nRc;
  543.  HANDLE hBuff;
  544.  HCURSOR hSaveCursor;
  545.  unsigned int bufsize;
  546.  char *Buff;
  547.  int ch1;
  548.  OFSTRUCT OfStruct;
  549.  struct stat fst;
  550.  
  551.  /* display the wait cursor                                            */
  552.  hSaveCursor = SetCursor(hHourGlass);
  553.  
  554.  /* open the file                                                    */
  555.  ch1 = OpenFile( FName, &OfStruct, OF_READ );
  556.  if( ch1 != -1 )
  557.  {
  558.   /* get the file statistics                                        */
  559.   fstat( ch1, &fst );
  560.  
  561.   /* set the buffer to the size of the file plus one                */
  562.   bufsize = (unsigned int) fst.st_size;
  563.  
  564.   /* allocate space for the read buffer and lock it                    */
  565.   hBuff = LocalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (WORD) (bufsize+1) );
  566.   if( hBuff == NULL )
  567.   {
  568.    SetCursor(hSaveCursor);
  569.    return IDS_ERR_NOEXEC;
  570.   }
  571.   Buff = (char *) LocalLock( hBuff );
  572.  
  573.   /*read the file and close it                                        */
  574.   if( read( ch1, Buff, bufsize ) == -1 )
  575.   {
  576.    LocalUnlock( hBuff );
  577.    LocalFree( hBuff );
  578.    SetCursor(hSaveCursor);
  579.    return IDS_ERR_LOAD;
  580.   }
  581.   close( ch1 );
  582.  
  583.   fl = 0;
  584.  
  585.   if( ( nRc = BufToTop( Buff, &Buff ) ) != 0 )
  586.   {
  587.    /* release the memory allocated for the buffer                    */
  588.    LocalUnlock( hBuff );
  589.    LocalFree( hBuff );
  590.    SetCursor(hSaveCursor);
  591.    return nRc;
  592.   }
  593.   /* set flags                                                         */
  594.   for( i=0; i<nsteps; i++ ) kfl[i] = 1;
  595.   /* check if model contains user-defined kinetic types                */
  596.   /* if there are any, check if they have to be read                */
  597.   for( i=0; i<nsteps; i++ )
  598.    if( (kinetu[i] >= MAX_TYP) )
  599.    {
  600.     /* look for a form-feed                                            */
  601.     Buff = strchr( Buff, '\f' );
  602.     Buff = BufToTree( ++Buff );
  603.     for( j=0, ty=-1; j<nudf; j++ )
  604.      if( lstrcmp( (LPSTR) tree[j].descr, (LPSTR) tr.descr ) == 0 )
  605.      {
  606.       ty = j;
  607.       break;
  608.      }
  609.     if( ty == -1 )
  610.     {
  611.      if( (nRc=addtr( i )) !=0 ) return nRc;
  612.      fl = 1;
  613.     }
  614.     else
  615.      for( j=i,k=kinetu[i]; j<nsteps; j++ )
  616.       if( (kinetu[j]==k) && (kfl[j]) )
  617.       {
  618.        kinetu[j] = MAX_TYP+ty;
  619.        kfl[j] = 0;
  620.       }
  621.    }
  622.  
  623.    SetCursor(hSaveCursor);
  624.  
  625. #ifdef GWTOP
  626.   if( fl )
  627.   {
  628.    LoadString( hInst, IDS_INF_NEWKIN, szString, sizeof(szString) );
  629.    MessageBox( NULL, szString, (LPSTR) "GEPASI - Topology", MB_ICONINFORMATION );
  630.   }
  631. #endif
  632.  
  633.   return 0;
  634.  }
  635.  else
  636.  {
  637.   SetCursor(hSaveCursor);
  638.   return IDS_ERR_LOAD;
  639.  }
  640. }
  641.  
  642.